package com.lvan.rabbit.producer.mode4_routingdirect;

import com.lvan.rabbit.utils.RabbitMQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * 路由模式（静态路由）
 * @author Lvan
 */
public class RoutDirect1 {
    public static void main(String[] args) throws IOException {
        // 获取连接
        Connection connection = RabbitMQUtil.getConnection();
        // 获取连接通道对象
        Channel channel = connection.createChannel();
        // 通过通道声明交换机
        // 参数1：通道名
        // 参数2：交换机模式，direct—路由模式
        channel.exchangeDeclare("logs_direct", "direct");
        String routingKey = "warning";
        // 发送消息
        channel.basicPublish("logs_direct", routingKey, null, (routingKey + ": This is direct message").getBytes());
        // 关闭连接
        RabbitMQUtil.closeConnectionAndChanel(channel, connection);
    }
}
